package com.link.base.base.home.controller;

import com.link.base.base.home.model.PageConfig;
import com.link.base.base.home.service.PageConfigService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: weixuan
 * created: 2019-01-12
 * comments: 首页菜单栏Controller
 */
@Controller
@RequestMapping("/link/pageConfig")
public class PageConfigController extends BasicController<PageConfig> {

    @Resource
    private PageConfigService pageConfigService;

    @Override
    public BasicService<PageConfig> getBasicService() throws Exception {
        return pageConfigService;
    }

    /**
     *
     * @author weixuan
     * @created 2019-01-12
     * @throws Exception
     * 查询用户自定义首页菜单栏，如果不存在默认系统新增初始化
     */

    @RequestMapping(value = "/initUserConfig")
    @ResponseBody
    public Map<String, Object> initUserConfig(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<PageConfig> pageConfigList = pageConfigService.initUserConfig();
            result.put("success", true);
            result.put("rows", pageConfigList);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }


}
